<?php
namespace Admin\Controller;
use Think\Controller;
class PhoneController extends BaseController {
    public function index(){
      $info = D('phone_index_main');
      $getinfos = $info ->select();
      // var_dump($getinfos);die;
      $this->assign('maininfo',$getinfos);
        $this->display();
    }
    public function getmaininfo(){
       if(IS_AJAX){
            $id = $_POST['id'];
            $db=D('phone_index_main');
            $resu = $db->find($id);
            if($resu){
              $res['main'] = $resu;
              $this->ajaxReturn($res);
            }else{
              $res['msg'] = '操作失败';
              $this->ajaxReturn($res);
            }
        }
    }

     public function ajax_uploadMain(){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     './Public/Uploads/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();
           // http://127.0.0.1/lrw/index.php/admin/index/index.html
           if ($info) {
            $path = 'http://'.$_SERVER['SERVER_NAME'].'/Public/Uploads/'.$info['uploadMain']['savepath'].$info['uploadMain']['savename'];
            $this->ajaxReturn($path);
           }else{
            $path = false;
            $this->ajaxReturn($path);
           }

    }

    public function mainsave(){

        if(IS_AJAX){
            $db=D('phone_index_main');
            $data['id'] = $_POST['id'];
            $data['descript'] = $_POST['descript'];
            $data['title'] = $_POST['title'];
            $data['span'] = $_POST['span'];
            $data['imgurl'] = $_POST['mainurlinput'];
            $resu = $db->save($data);
            if($resu){
              $res['msg'] = '修改成功';
              $this->ajaxReturn($res);
            }else{
              $res['msg'] = '修改失败';
              $this->ajaxReturn($res);
            }
        }
     }

    public function upload(){
      $info = D('apkandipa');
      $getinfos = $info ->select();
      // var_dump($getinfos);die;
      $this->assign('maininfo',$getinfos);
        $this->display();
    }

     public function ajax_uploadapkipa(){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('apk','ipa','app','zip','png');// 设置附件上传类型
            $upload->rootPath  =     './Public/Version/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            // 上传文件
            $info   =   $upload->upload();
           // http://127.0.0.1/lrw/index.php/admin/index/index.html
           if ($info) {
            $path['allurl'] = 'http://'.$_SERVER['SERVER_NAME'].'/index.php/home/index/';
            $path['queurl'] = 'Public/Version/'.$info['uploadapkipa']['savepath'].$info['uploadapkipa']['savename'];
            $this->ajaxReturn($path);
           }else{
            $path = false;
            $this->ajaxReturn($path);
           }
    }
    public function getapkipainfo(){
       if(IS_AJAX){
            $id = $_POST['id'];
            $db=D('apkandipa');
            $resu = $db->find($id);
            if($resu){
              $res['apkipa'] = $resu;
              $this->ajaxReturn($res);
            }else{
              $res['msg'] = '操作失败';
              $this->ajaxReturn($res);
            }
        }
    }
    public function uploadsave(){
        if(IS_AJAX){
            $db=D('apkandipa');
            $data['id'] = $_POST['id'];
            $data['url'] = $_POST['url'];
            $data['title'] = $_POST['title'];
            $data['queurl'] = $_POST['queurl'];
            $resu = $db->save($data);
            if($resu){
              $res['msg'] = '修改成功';
              $this->ajaxReturn($res);
            }else{
              $res['msg'] = '修改失败';
              $this->ajaxReturn($res);
            }
        }
     }


}